package sim.tests.games.sailing;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;

import sim.Image;
import sim.Updateable;

public class Boat implements Updateable
{
	float dx;
	float dy;
	float x;
	float y;
	Image sprite;
	Image sail;
	public Boat(float x, float y)
	{
		this.x = x;
		this.y = y;
		
		sail = new Image("gun.png");
		sail.setSize(1, 1);
		
		sprite = new Image("boat.png");
		sprite.setSize(1f, 1f);
		
		
	}
	@Override
	public void draw()
	{
		
		sprite.draw(x, y);
		sail.draw(x, y);
		
	}
	@Override
	public void update(float delta)
	{
		
		
		if (Gdx.input.isKeyPressed(Input.Keys.D))
		{
			dx += 0.2f * delta;				
		}
		
		if (Gdx.input.isKeyPressed(Input.Keys.A))
		{
		 dx -= 0.2f * delta;	
		}
		
		if (Gdx.input.isKeyPressed(Input.Keys.W))
		{
			
		 dy += 0.2 * delta;
		}
		
		if (Gdx.input.isKeyPressed(Input.Keys.S))
		{
			
		 dy -= 0.2 * delta;
		}
		
		if (Gdx.input.isKeyPressed(Input.Keys.RIGHT))
		{
			sail.rotate((float) (-160 * delta));
			
		}
		
		if (Gdx.input.isKeyPressed(Input.Keys.LEFT))
		{
			sail.rotate((float) (160 * delta));
			
		}
		
		dy *= 0.93;
		
		dx *= 0.93;

		x += dx;
		y += dy;
		
	}
}
